<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CoreController
 *
 * @author Zelic
 */
class ZF_AdminController extends Zend_Controller_Action {

    public function preDispatch() {
        $auth = Zend_Auth::getInstance();
    if (!$auth->hasIdentity()) {
            if ($this->_request->getActionName() != 'login') {
                $this->_redirect('/admin/auth/login');
            }
        }
    }

    public function init() {
        $module = $this->_request->getModuleName();
        $this->view->module = $module;
        $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
        $this->view->baseUrl = $baseUrl;
        $option = array("layout" => "index", "layoutPath" => APPLICATION_PATH . "/modules/admin/layouts/scripts", "module" => "default");
        Zend_Layout::startMvc($option);
        $user = Zend_Auth::getInstance()->getIdentity();
        if ($user != null   ){
            $this->view->username = $user->username;
        }
        $this->controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
        $this->module = Zend_Controller_Front::getInstance()->getRequest()->getModuleName();
        $this->baseUrl = Zend_Controller_Front::getInstance()->getRequest()->getBaseUrl();
    }
    public function changeRouter($request,$map)
    {
     
      $configs = new Zend_Config_Ini(APPLICATION_PATH.'/configs/routers.ini','config',true);
      $configs->routes->index->defaults = array(
         "module" =>$request['module'],
         "controller" =>$request['controller'],
         "action"   => $request['action'],
      );
   
      $configs->routes->index->map = $map;
      
      $write = new Zend_Config_Writer_Ini();
      $write->write(APPLICATION_PATH.'/configs/routers.ini',$configs);
   


    }

}

?>
